home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / internet / amitcp3.0b / netinclude / rpc / svc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-21  |  9.2 KB  |  280 lines

  1. /*
  2.  * $Id: svc.h,v 1.2 1993/11/10 01:09:23 jraja Exp $
  3.  *
  4.  * $Log: svc.h,v $
  5.  * Revision 1.2  1993/11/10  01:09:23  jraja
  6.  * ANSI prototypes.
  7.  *
  8.  */
  9. /* @(#)svc.h    2.2 88/07/29 4.0 RPCSRC; from 1.20 88/02/08 SMI */
  10. /*
  11.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  12.  * unrestricted use provided that this legend is included on all tape
  13.  * media and as a part of the software program in whole or part.  Users
  14.  * may copy or modify Sun RPC without charge, but are not authorized
  15.  * to license or distribute it to anyone else except as part of a product or
  16.  * program developed by the user.
  17.  * 
  18.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  19.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  20.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  21.  * 
  22.  * Sun RPC is provided with no support and without any obligation on the
  23.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  24.  * modification or enhancement.
  25.  * 
  26.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  27.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  28.  * OR ANY PART THEREOF.
  29.  * 
  30.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  31.  * or profits or other special, indirect and consequential damages, even if
  32.  * Sun has been advised of the possibility of such damages.
  33.  * 
  34.  * Sun Microsystems, Inc.
  35.  * 2550 Garcia Avenue
  36.  * Mountain View, California  94043
  37.  */
  38.  
  39. /*
  40.  * svc.h, Server-side remote procedure call interface.
  41.  *
  42.  * Copyright (C) 1984, Sun Microsystems, Inc.
  43.  */
  44.  
  45. #ifndef __SVC_HEADER__
  46. #define __SVC_HEADER__
  47.  
  48. /*
  49.  * This interface must manage two items concerning remote procedure calling:
  50.  *
  51.  * 1) An arbitrary number of transport connections upon which rpc requests
  52.  * are received.  The two most notable transports are TCP and UDP;  they are
  53.  * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
  54.  * they in turn call xprt_register and xprt_unregister.
  55.  *
  56.  * 2) An arbitrary number of locally registered services.  Services are
  57.  * described by the following four data: program number, version number,
  58.  * "service dispatch" function, a transport handle, and a boolean that
  59.  * indicates whether or not the exported program should be registered with a
  60.  * local binder service;  if true the program's number and version and the
  61.  * port number from the transport handle are registered with the binder.
  62.  * These data are registered with the rpc svc system via svc_register.
  63.  *
  64.  * A service's dispatch function is called whenever an rpc request comes in
  65.  * on a transport.  The request's program and version numbers must match
  66.  * those of the registered service.  The dispatch function is passed two
  67.  * parameters, struct svc_req * and SVCXPRT *, defined below.
  68.  */
  69.  
  70. enum xprt_stat {
  71.     XPRT_DIED,
  72.     XPRT_MOREREQS,
  73.     XPRT_IDLE
  74. };
  75.  
  76. /*
  77.  * Server side transport handle
  78.  */
  79. typedef struct SVCXPRT {
  80.     int        xp_sock;
  81.     u_short        xp_port;     /* associated port number */
  82.     struct xp_ops {
  83.         bool_t    (*xp_recv)(struct SVCXPRT *xprt, struct rpc_msg *msg);     /* receive incomming requests */
  84.         enum xprt_stat (*xp_stat)(struct SVCXPRT *xprt); /* get transport status */
  85.         bool_t    (*xp_getargs)(struct SVCXPRT *xprt, xdrproc_t xargs,
  86.                       void * argsp); /* get arguments */
  87.         bool_t    (*xp_reply)(struct SVCXPRT *xprt,
  88.                     struct rpc_msg *msg);  /* send reply */
  89.         bool_t    (*xp_freeargs)(struct SVCXPRT *xprt, xdrproc_t xargs, 
  90.                       void * argsp);/* free mem allocated for args */
  91.         void    (*xp_destroy)(struct SVCXPRT *xprt); /* destroy this struct */
  92.     } *xp_ops;
  93.     long        xp_addrlen;     /* length of remote address */
  94.     struct sockaddr_in xp_raddr;     /* remote address */
  95.     struct opaque_auth xp_verf;     /* raw response verifier */
  96.     caddr_t        xp_p1;         /* private */
  97.     caddr_t        xp_p2;         /* private */
  98. } SVCXPRT;
  99.  
  100. /*
  101.  *  Approved way of getting address of caller
  102.  */
  103. #define svc_getcaller(x) (&(x)->xp_raddr)
  104.  
  105. /*
  106.  * Operations defined on an SVCXPRT handle
  107.  *
  108.  * SVCXPRT        *xprt;
  109.  * struct rpc_msg    *msg;
  110.  * xdrproc_t         xargs;
  111.  * caddr_t         argsp;
  112.  */
  113. #define SVC_RECV(xprt, msg)                \
  114.     (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  115. #define svc_recv(xprt, msg)                \
  116.     (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  117.  
  118. #define SVC_STAT(xprt)                    \
  119.     (*(xprt)->xp_ops->xp_stat)(xprt)
  120. #define svc_stat(xprt)                    \
  121.     (*(xprt)->xp_ops->xp_stat)(xprt)
  122.  
  123. #define SVC_GETARGS(xprt, xargs, argsp)            \
  124.     (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  125. #define svc_getargs(xprt, xargs, argsp)            \
  126.     (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  127.  
  128. #define SVC_REPLY(xprt, msg)                \
  129.     (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  130. #define svc_reply(xprt, msg)                \
  131.     (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  132.  
  133. #define SVC_FREEARGS(xprt, xargs, argsp)        \
  134.     (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  135. #define svc_freeargs(xprt, xargs, argsp)        \
  136.     (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  137.  
  138. #define SVC_DESTROY(xprt)                \
  139.     (*(xprt)->xp_ops->xp_destroy)(xprt)
  140. #define svc_destroy(xprt)                \
  141.     (*(xprt)->xp_ops->xp_destroy)(xprt)
  142.  
  143.  
  144. /*
  145.  * Service request
  146.  */
  147. struct svc_req {
  148.     u_long        rq_prog;    /* service program number */
  149.     u_long        rq_vers;    /* service protocol version */
  150.     u_long        rq_proc;    /* the desired procedure */
  151.     struct opaque_auth rq_cred;    /* raw creds from the wire */
  152.     caddr_t        rq_clntcred;    /* read only cooked cred */
  153.     SVCXPRT    *rq_xprt;        /* associated transport */
  154. };
  155.  
  156.  
  157. /*
  158.  * Service registration
  159.  *
  160.  *  protocol is like TCP or UDP, zero means do not register 
  161.  */
  162. extern bool_t    svc_register(SVCXPRT * xprt, u_long prog, u_long vers,
  163.                  void (* dispatch)(struct svc_req *, SVCXPRT *),
  164.                  int protocol);
  165.  
  166. /*
  167.  * Service un-registration
  168.  */
  169. extern void    svc_unregister(u_long prog, u_long vers);
  170.  
  171. /*
  172.  * Transport registration.
  173.  */
  174. extern void    xprt_register(SVCXPRT * xprt);
  175.  
  176. /*
  177.  * Transport un-register
  178.  */
  179. extern void    xprt_unregister(SVCXPRT * xprt);
  180.  
  181.  
  182.  
  183.  
  184. /*
  185.  * When the service routine is called, it must first check to see if it
  186.  * knows about the procedure;  if not, it should call svcerr_noproc
  187.  * and return.  If so, it should deserialize its arguments via 
  188.  * SVC_GETARGS (defined above).  If the deserialization does not work,
  189.  * svcerr_decode should be called followed by a return.  Successful
  190.  * decoding of the arguments should be followed the execution of the
  191.  * procedure's code and a call to svc_sendreply.
  192.  *
  193.  * Also, if the service refuses to execute the procedure due to too-
  194.  * weak authentication parameters, svcerr_weakauth should be called.
  195.  * Note: do not confuse access-control failure with weak authentication!
  196.  *
  197.  * NB: In pure implementations of rpc, the caller always waits for a reply
  198.  * msg.  This message is sent when svc_sendreply is called.  
  199.  * Therefore pure service implementations should always call
  200.  * svc_sendreply even if the function logically returns void;  use
  201.  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
  202.  * for the abuse of pure rpc via batched calling or pipelining.  In the
  203.  * case of a batched call, svc_sendreply should NOT be called since
  204.  * this would send a return message, which is what batching tries to avoid.
  205.  * It is the service/protocol writer's responsibility to know which calls are
  206.  * batched and which are not.  Warning: responding to batch calls may
  207.  * deadlock the caller and server processes!
  208.  */
  209.  
  210. extern bool_t    svc_sendreply(SVCXPRT * xprt, xdrproc_t xdr_results,
  211.                   caddr_t xdr_location);
  212. extern void    svcerr_decode(SVCXPRT * xprt);
  213. extern void    svcerr_weakauth(SVCXPRT * xprt);
  214. extern void    svcerr_noproc(SVCXPRT * xprt);
  215. extern void    svcerr_progvers(SVCXPRT * xprt, 
  216.                 u_long low_vers, u_long high_vers);
  217. extern void    svcerr_auth(SVCXPRT * xprt, enum auth_stat why);
  218. extern void    svcerr_noprog(SVCXPRT * xprt);
  219. extern void    svcerr_systemerr(SVCXPRT * xprt);
  220.     
  221. /*
  222.  * Lowest level dispatching -OR- who owns this process anyway.
  223.  * Somebody has to wait for incoming requests and then call the correct
  224.  * service routine.  The routine svc_run does infinite waiting; i.e.,
  225.  * svc_run never returns.
  226.  * Since another (co-existant) package may wish to selectively wait for
  227.  * incoming calls or other events outside of the rpc architecture, the
  228.  * routine svc_getreq is provided.  It must be passed readfds, the
  229.  * "in-place" results of a select system call (see select, section 2).
  230.  */
  231.  
  232. /*
  233.  * Global keeper of rpc service descriptors in use
  234.  * dynamic; must be inspected before each call to select 
  235.  */
  236. #ifdef FD_SETSIZE
  237. extern fd_set svc_fdset;
  238. #define svc_fds svc_fdset.fds_bits[0]    /* compatibility */
  239. #else
  240. extern int svc_fds;
  241. #endif /* def FD_SETSIZE */
  242.  
  243. /*
  244.  * a small program implemented by the svc_rpc implementation itself;
  245.  * also see clnt.h for protocol numbers.
  246.  */
  247. extern void rpctest_service();
  248.  
  249. extern void    svc_getreq(int rdfds);
  250. extern void    svc_getreqset(fd_set * readfds); /* takes fdset instead of int */
  251. extern void    svc_run(void);      /* never returns */
  252.  
  253. /*
  254.  * Socket to use on svcxxx_create call to get default socket
  255.  */
  256. #define    RPC_ANYSOCK    -1
  257.  
  258. /*
  259.  * These are the existing service side transport implementations
  260.  */
  261.  
  262. /*
  263.  * Memory based rpc for testing and timing.
  264.  */
  265. extern SVCXPRT *svcraw_create(void);
  266.  
  267. /*
  268.  * Udp based rpc.
  269.  */
  270. extern SVCXPRT *svcudp_create(int sock);
  271. extern SVCXPRT *svcudp_bufcreate(int sock, u_int sendsz, u_int recvsz);
  272.  
  273. /*
  274.  * Tcp based rpc.
  275.  */
  276. extern SVCXPRT *svctcp_create(int sock, u_int sendsize, u_int recvsize);
  277.  
  278.  
  279. #endif /* !__SVC_HEADER__ */
  280.